<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2018/12/4
 * Time: 12:05
 */

namespace app\common\lib\astrolog;
/**
 * 20181223 星体影响力成就破坏，把tr引动部分的月亮的引动效果全部去掉
 * Class CaclByTopic
 * @package app\common\lib\astrolog
 */
class CaclByTopic
{
    /**
     * 获取某主题下，星体的关联度，破坏值，成就值
     * @param array $source
     * @param array $option
     * @return array
     */
    public function init($source = [], $option = [])
    {
        $result = [
            'relation' => 0,
            'destory' => 0,
            'achievement' => 0,
        ];
        $result['relation'] = $this->getPlanetRelationScore($source, $option);
        $result['destory'] = $this->getPlanetDestoryScore($source, $option);
        $result['achievement'] = $this->getPlanetAchievementScore($source, $option);

        return $result;
    }

    /**
     * 星体在某方面的关联度
     * @param array $source
     * transits_data 行运盘数据
     * thirdprogressed_data 三限盘数据
     * @param array $option
     * target int 目标星体
     * house array 征象宫
     * planet int 征象星
     * @return float
     */
    public function getPlanetRelationScore($source = [], $option = [])
    {
        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tr_planet2 = $source['transits_data'][0]['planets'];// 行运内盘数据 -本命
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘
        $pid = $option['target'];
        $limit = $option['planet_type'] ?? false;

        $score = 0;
        //	tp
        // 目标星三限落宫
        $target_in_house = $tp_planet[$pid]['in_house_id'];
        // 星体落在征象宫+3
        if (in_array($target_in_house, $option['house']))
        {
            $score += 3;
            // （若仅有该星落征象宫+5）
            if ($source['transits_data'][1]['houses'][$target_in_house]['have_planet_num'] == 1)
            {
                $score += 5;
            }
            // 有相位
            if (!empty($tp_planet[$pid]['phase']))
            {
                foreach ($tp_planet[$pid]['phase'] as $phase)
                {
                    // 太阳9月亮9金星4水星4火星3其它1
                    switch ($phase['id'])
                    {
                        case 0:
                            $temp = 9;
                            break;
                        case 1:
                            $temp = 9;
                            break;
                        case 2:
                            $temp = 4;
                            break;
                        case 3:
                            $temp = 4;
                            break;
                        case 4:
                            $temp = 3;
                            break;
                        default:
                            $temp = 1;
                            break;
                    }
                    switch ($phase['phase_e'])
                    {
                        case 0:
                            $modulus = 1;
                            break;
                        case 60:
                            $modulus = 0.8;
                            break;
                        case 90:
                            $modulus = 0.9;
                            break;
                        case 120:
                            $modulus = 0.9;
                            break;
                        case 180:
                            $modulus = 0.9;
                            break;
                        default :
                            $modulus = 0;
                            break;
                    }

                    $score += $temp * $modulus;
                }
            }
        } // 星体不在征象宫
        else
        {
            if (!empty($tp_planet[$pid]['phase']))
            {
                $is_phase_option_house_plaent = false;// 与征象宫内星有相位
                foreach ($tp_planet[$pid]['phase'] as $phase)
                {
                    // 与征象宫内星有相位
                    if (in_array($tp_planet[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 太阳9月亮9金星4水星4火星3其它1
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp = 9;
                                break;
                            case 1:
                                $temp = 9;
                                break;
                            case 2:
                                $temp = 4;
                                break;
                            case 3:
                                $temp = 4;
                                break;
                            case 4:
                                $temp = 3;
                                break;
                            default:
                                $temp = 1;
                                break;
                        }
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $modulus = 1;
                                break;
                            case 60:
                                $modulus = 0.8;
                                break;
                            case 90:
                                $modulus = 0.9;
                                break;
                            case 120:
                                $modulus = 0.9;
                                break;
                            case 180:
                                $modulus = 0.9;
                                break;
                            default :
                                $modulus = 0;
                                break;
                        }

                        $score += $temp * $modulus;

                        $is_phase_option_house_plaent = true;
                    }
                }
                // 如月亮未在征象宫内，该星在与征象宫星体成相的同时与月亮成相
                if (!in_array($tp_planet[1]['in_house_id'], $option['house'])
                    && $is_phase_option_house_plaent === true
                    && isset($tp_planet[$pid]['phase'][$pid . '-1'])
                )
                {
                    // 合8刑8冲8拱7六分6
                    switch ($tp_planet[$pid]['phase'][$pid . '-1']['phase_e'])
                    {
                        case 0:
                            $temp = 8;
                            break;
                        case 60:
                            $temp = 6;
                            break;
                        case 90:
                            $temp = 8;
                            break;
                        case 120:
                            $temp = 7;
                            break;
                        case 180:
                            $temp = 8;
                            break;
                        default :
                            $temp = 0;
                            break;
                    }
                    $score += $temp;
                }
            }
        }
        // 星体与征象星成相
        if (($limit === false && $pid != 1) && isset($tp_planet[$pid]['phase'][$pid . '-' . $option['planet']]))
        {
            // 合14，拱刑冲12，六分10
            switch ($tp_planet[$pid]['phase'][$pid . '-' . $option['planet']]['phase_e'])
            {
                case 0:
                    $temp = 14;
                    break;
                case 60:
                    $temp = 10;
                    break;
                case 90:
                    $temp = 14;
                    break;
                case 120:
                    $temp = 14;
                    break;
                case 180:
                    $temp = 14;
                    break;
                default :
                    $temp = 0;
                    break;
            }
            // （若征象星在征象宫内，此得分折半）
            if (in_array($tp_planet[$option['planet']]['in_house_id'], $option['house']))
            {
                $temp *= 0.5;
            }
            $score += $temp;
        }
        //	tr
        //		星体落在征象宫+3
        if (in_array($tr_planet1[$pid]['in_house_id'], $option['house']))
        {
            $score += 3;
            // 有相位
            if (!empty($tr_planet1[$pid]['phase']))
            {
                foreach ($tr_planet1[$pid]['phase'] as $phase)
                {
                    // 太阳9月亮9金星4水星4火星3其它1
                    switch ($phase['id'])
                    {
                        case 0:
                            $temp = 9;
                            break;
                        case 1:
                            $temp = 9;
                            break;
                        case 2:
                            $temp = 4;
                            break;
                        case 3:
                            $temp = 4;
                            break;
                        case 4:
                            $temp = 3;
                            break;
                        default:
                            $temp = 1;
                            break;
                    }
                    switch ($phase['phase_e'])
                    {
                        case 0:
                            $modulus = 1;
                            break;
                        case 60:
                            $modulus = 0.8;
                            break;
                        case 90:
                            $modulus = 0.9;
                            break;
                        case 120:
                            $modulus = 0.9;
                            break;
                        case 180:
                            $modulus = 0.9;
                            break;
                        default :
                            $modulus = 0;
                            break;
                    }
                    $score += $temp * $modulus;
                }
            }
        } // 星体不在征象宫
        else
        {
            if (!empty($tr_planet1[$pid]['phase']))
            {
                foreach ($tr_planet1[$pid]['phase'] as $phase)
                {
                    // 与征象宫内星有相位
                    if (in_array($tr_planet1[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 太阳9月亮9金星4水星4火星3其它1
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp = 9;
                                break;
                            case 1:
                                $temp = 9;
                                break;
                            case 2:
                                $temp = 4;
                                break;
                            case 3:
                                $temp = 4;
                                break;
                            case 4:
                                $temp = 3;
                                break;
                            default:
                                $temp = 1;
                                break;
                        }
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $modulus = 1;
                                break;
                            case 60:
                                $modulus = 0.8;
                                break;
                            case 90:
                                $modulus = 0.9;
                                break;
                            case 120:
                                $modulus = 0.9;
                                break;
                            case 180:
                                $modulus = 0.9;
                                break;
                            default :
                                $modulus = 0;
                                break;
                        }
                        $score += $temp * $modulus;
                    }
                }
            }
        }
        // 星体与征象星成相
        if (isset($tr_planet1[$pid]['phase'][$pid . '-' . $option['planet']]))
        {
            // 合14，拱刑冲12，六分10
            switch ($tr_planet1[$pid]['phase'][$pid . '-' . $option['planet']]['phase_e'])
            {
                case 0:
                    $temp = 14;
                    break;
                case 60:
                    $temp = 10;
                    break;
                case 90:
                    $temp = 14;
                    break;
                case 120:
                    $temp = 14;
                    break;
                case 180:
                    $temp = 14;
                    break;
                default :
                    $temp = 0;
                    break;
            }
            // （若征象星在征象宫内，此得分折半）
            if (in_array($tr_planet1[$option['planet']]['in_house_id'], $option['house']))
            {
                $temp *= 0.5;
            }
            $score += $temp;
        }
        //	tr引动
        if (!empty($tr_planet1[$pid]['phase']))
        {
            // 日月水金火
            $planets = [0, 2, 3, 4];
            // 遍历该星的相位
            foreach ($tr_planet1[$pid]['phase'] as $phase)
            {
                // 仅限日月水金火木土天海冥
                if ($phase['id'] < 10)
                {
                    foreach ($planets as $p)
                    {
                        /**
                         * 日金水火月与同该星成相的本命某星成相
                         * $pid 为该星
                         * $p 为日月水金火之一
                         * $phase['id'] 为本命某星
                         */
                        if ($pid != $p && isset($tr_planet1[$p]['phase'][$p . '-' . $phase['id']]))
                        {
                            /**
                             * 计算原相位力量
                             */
                            // 太阳9月亮9金星4水星4火星3其它1
                            switch ($phase['id'])
                            {
                                case 0:
                                    $temp1 = 9;
                                    break;
                                case 1:
                                    $temp1 = 0;
                                    break;
                                case 2:
                                    $temp1 = 4;
                                    break;
                                case 3:
                                    $temp1 = 4;
                                    break;
                                case 4:
                                    $temp1 = 3;
                                    break;
                                default:
                                    $temp1 = 1;
                                    break;
                            }
                            $temp2 = 0;
                            switch ($phase['phase_e'])
                            {
                                case 0:
                                    $modulus = 1;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 14;
                                    }
                                    break;
                                case 60:
                                    $modulus = 0.8;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 10;
                                    }
                                    break;
                                case 90:
                                    $modulus = 0.9;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 12;
                                    }
                                    break;
                                case 120:
                                    $modulus = 0.9;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 12;
                                    }
                                    break;
                                case 180:
                                    $modulus = 0.9;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 12;
                                    }
                                    break;
                                default :
                                    $modulus = 0;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 0;
                                    }
                                    break;
                            }
                            // 若征象星在征象宫内，此得分折半
                            if (in_array($tr_planet2[$phase['id']]['in_house_id'], $option['house']))
                            {
                                $temp2 *= 0.5;
                            }
                            // 原相位力量
                            $or_score = $temp1 * $modulus + $temp2;

                            /**
                             * 计算激发系数
                             */
                            $phase_boot = $tr_planet1[$p]['phase'][$p . '-' . $phase['id']];
                            // 0.5度内1
                            if ($phase_boot['phase_orb'] <= 0.5)
                            {
                                $temp1 = 1;
                            }// 1度内0.95
                            elseif ($phase_boot['phase_orb'] <= 1)
                            {
                                $temp1 = 0.95;
                            }// 1.5度内0.9
                            elseif ($phase_boot['phase_orb'] <= 1)
                            {
                                $temp1 = 0.9;
                            }// 2度内0.8
                            elseif ($phase_boot['phase_orb'] <= 2)
                            {
                                $temp1 = 0.8;
                            } else
                            {
                                $temp1 = 0;
                            }
                            switch ($p)
                            {
                                case 0:
                                    $temp2 = 0.5;
                                    break;
                                case 1:
                                    $temp2 = 0.2;
                                    break;
                                case 2:
                                    $temp2 = 0.4;
                                    break;
                                case 3:
                                    $temp2 = 0.4;
                                    break;
                                case 4:
                                    $temp2 = 0.4;
                                    break;
                                default:
                                    $temp2 = 0;
                                    break;
                            }
                            switch ($phase_boot['phase_e'])
                            {
                                case 0:
                                    $temp3 = 1;
                                    break;
                                case 60:
                                    $temp3 = 0.8;
                                    break;
                                case 90:
                                    $temp3 = 0.9;
                                    break;
                                case 120:
                                    $temp3 = 0.9;
                                    break;
                                case 180:
                                    $temp3 = 0.9;
                                    break;
                                default :
                                    $temp3 = 0;
                                    break;
                            }
                            // 激发原相位的力量的百分比（计算原相位力量而后乘以激发系数）
                            $score += $or_score * $temp1 * $temp2 * $temp3;
                        }
                    }
                }
            }
        }
        // 本命该星落在征象宫，被tr引动
        if (in_array($tr_planet2[$pid]['in_house_id'], $option['house']))
        {
            if (!empty($tr_planet2[$pid]['phase']))
            {
                foreach ($tr_planet2[$pid]['phase'] as $phase)
                {
                    if ($phase['id'] < 10)
                    {
                        // 天海冥2，木土3，火3.5，（金水4，日5，月3，仅在慢星引动时记分）
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp1 = 5;
                                break;
                            case 1:
                                $temp1 = 0;
                                break;
                            case 2:
                                $temp1 = 4;
                                break;
                            case 3:
                                $temp1 = 4;
                                break;
                            case 4:
                                $temp1 = 3.5;
                                break;
                            case 5:
                                $temp1 = 3;
                                break;
                            case 6:
                                $temp1 = 3;
                                break;
                            case 7:
                                $temp1 = 2;
                                break;
                            case 8:
                                $temp1 = 2;
                                break;
                            case 9:
                                $temp1 = 2;
                                break;
                            default :
                                $temp1 = 0;
                                break;
                        }
                        // 合1拱0.9刑0.9冲0.9六分0.8
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $temp2 = 1;
                                break;
                            case 60:
                                $temp2 = 0.8;
                                break;
                            case 90:
                                $temp2 = 0.9;
                                break;
                            case 120:
                                $temp2 = 0.9;
                                break;
                            case 180:
                                $temp2 = 0.9;
                                break;
                            default :
                                $temp2 = 0;
                                break;
                        }
                        $score += $temp1 * $temp2;
                    }
                }
            }
        }// 本命该星未落在征象宫，但被过征象宫的tr星引动
        else
        {
            if (!empty($tr_planet2[$pid]['phase']))
            {
                foreach ($tr_planet2[$pid]['phase'] as $phase)
                {
                    if ($phase['id'] < 10 && in_array($tr_planet1[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 天海冥2，木土3，火3.5，（金水4，日5，月3，仅在慢星引动时记分）
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp1 = 5;
                                break;
                            case 1:
                                $temp1 = 0;
                                break;
                            case 2:
                                $temp1 = 4;
                                break;
                            case 3:
                                $temp1 = 4;
                                break;
                            case 4:
                                $temp1 = 3.5;
                                break;
                            case 5:
                                $temp1 = 3;
                                break;
                            case 6:
                                $temp1 = 3;
                                break;
                            case 7:
                                $temp1 = 2;
                                break;
                            case 8:
                                $temp1 = 2;
                                break;
                            case 9:
                                $temp1 = 2;
                                break;
                            default :
                                $temp1 = 0;
                                break;
                        }
                        // 合1拱0.9刑0.9冲0.9六分0.8
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $temp2 = 1;
                                break;
                            case 60:
                                $temp2 = 0.8;
                                break;
                            case 90:
                                $temp2 = 0.9;
                                break;
                            case 120:
                                $temp2 = 0.9;
                                break;
                            case 180:
                                $temp2 = 0.9;
                                break;
                            default :
                                $temp2 = 0;
                                break;
                        }
                        $score += $temp1 * $temp2;
                    }
                }
            }
        }

        return $score;
    }

    /**
     * 星体对某方面的破坏度（火土天海冥）
     * @param array $source
     * @param array $option
     * target int 目标星体
     * house int 征象宫
     * planet int 征象星
     * @return float
     */
    public function getPlanetDestoryScore($source = [], $option = [])
    {
        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tr_planet2 = $source['transits_data'][0]['planets'];// 行运内盘数据 -本命
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘
        $pid = $option['target'];
        $limit = $option['planet_type'] ?? false;

        $score = 0;
        //	tp
        // 目标星三限落宫
        $target_in_house = $tp_planet[$pid]['in_house_id'];
        // 星体落在征象宫+3
        if (in_array($target_in_house, $option['house']))
        {
            // 若该星体是火土天海冥
            if (in_array($pid, [4, 6, 7, 8, 9]))
            {
                $score += 3;
                // （若仅有该星落征象宫+5）
                if ($source['transits_data'][1]['houses'][$target_in_house]['have_planet_num'] == 1)
                {
                    $score += 5;
                }
                // 有相位
                if (!empty($tp_planet[$pid]['phase']))
                {
                    foreach ($tp_planet[$pid]['phase'] as $phase)
                    {
                        // 太阳9月亮9金星4水星4火星3其它1
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp = 9;
                                break;
                            case 1:
                                $temp = 9;
                                break;
                            case 2:
                                $temp = 4;
                                break;
                            case 3:
                                $temp = 4;
                                break;
                            case 4:
                                $temp = 3;
                                break;
                            default:
                                $temp = 1;
                                break;
                        }
                        // 合0.6拱0.3刑1.2冲1.2六分0.2
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $modulus = 0.6;
                                break;
                            case 60:
                                $modulus = 0.2;
                                break;
                            case 90:
                                $modulus = 1.2;
                                break;
                            case 120:
                                $modulus = 0.3;
                                break;
                            case 180:
                                $modulus = 1.2;
                                break;
                            default :
                                $modulus = 0;
                                break;
                        }
                        $score += $temp * $modulus;
                    }
                }
            }
        } // 星体不在征象宫
        else
        {
            if (!empty($tp_planet[$pid]['phase']))
            {
                $is_phase_option_house_plaent = false;// 与征象宫内星有相位
                foreach ($tp_planet[$pid]['phase'] as $phase)
                {
                    // 与征象宫内星有相位
                    if (in_array($tp_planet[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 太阳9月亮9金星4水星4火星3其它1
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp = 9;
                                break;
                            case 1:
                                $temp = 9;
                                break;
                            case 2:
                                $temp = 4;
                                break;
                            case 3:
                                $temp = 4;
                                break;
                            case 4:
                                $temp = 3;
                                break;
                            default:
                                $temp = 1;
                                break;
                        }
                        // 合0.6拱0.3刑1.5冲1.5六分0.2
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $modulus = 0.6;
                                break;
                            case 60:
                                $modulus = 0.2;
                                break;
                            case 90:
                                $modulus = 1.5;
                                break;
                            case 120:
                                $modulus = 0.3;
                                break;
                            case 180:
                                $modulus = 1.5;
                                break;
                            default :
                                $modulus = 0;
                                break;
                        }
                        $score += $temp * $modulus;

                        $is_phase_option_house_plaent = true;
                    }
                }
                // 如月亮未在征象宫内，该星在与征象宫星体成相的同时与月亮成相
                if (!in_array($tp_planet[1]['in_house_id'], $option['house'])
                    && $is_phase_option_house_plaent === true
                    && isset($tp_planet[$pid]['phase'][$pid . '-1'])
                )
                {
                    // 刑1冲1合0.6拱0.3六分0.3
                    switch ($tp_planet[$pid]['phase'][$pid . '-1']['phase_e'])
                    {
                        case 0:
                            $temp = 0.6;
                            break;
                        case 60:
                            $temp = 0.3;
                            break;
                        case 90:
                            $temp = 1;
                            break;
                        case 120:
                            $temp = 0.3;
                            break;
                        case 180:
                            $temp = 1;
                            break;
                        default :
                            $temp = 0;
                            break;
                    }

                    $score += $temp;
                }
            }
        }
        // 星体与征象星成相
        if (($limit === false && $pid != 1) && isset($tp_planet[$pid]['phase'][$pid . '-' . $option['planet']]))
        {
            // 合5，刑冲12，拱六分3
            switch ($tp_planet[$pid]['phase'][$pid . '-' . $option['planet']]['phase_e'])
            {
                case 0:
                    $temp = 5;
                    break;
                case 60:
                    $temp = 3;
                    break;
                case 90:
                    $temp = 12;
                    break;
                case 120:
                    $temp = 3;
                    break;
                case 180:
                    $temp = 12;
                    break;
                default :
                    $temp = 0;
                    break;
            }
            // （若征象星在征象宫内，此得分折半）
            if (in_array($tp_planet[$option['planet']]['in_house_id'], $option['house']))
            {
                $temp *= 0.5;
            }
            $score += $temp;
        }
        //	tr
        //		星体落在征象宫+3
        if (in_array($tr_planet1[$pid]['in_house_id'], $option['house']))
        {
            $score += 3;
            // 有相位
            if (!empty($tr_planet1[$pid]['phase']))
            {
                foreach ($tr_planet1[$pid]['phase'] as $phase)
                {
                    // 太阳9月亮9金星4水星4火星3其它1
                    switch ($phase['id'])
                    {
                        case 0:
                            $temp = 9;
                            break;
                        case 1:
                            $temp = 9;
                            break;
                        case 2:
                            $temp = 4;
                            break;
                        case 3:
                            $temp = 4;
                            break;
                        case 4:
                            $temp = 3;
                            break;
                        default:
                            $temp = 1;
                            break;
                    }
                    // 合1拱0.9刑0.9冲0.9六分0.8
                    switch ($phase['phase_e'])
                    {
                        case 0:
                            $modulus = 1;
                            break;
                        case 60:
                            $modulus = 0.8;
                            break;
                        case 90:
                            $modulus = 0.9;
                            break;
                        case 120:
                            $modulus = 0.9;
                            break;
                        case 180:
                            $modulus = 0.9;
                            break;
                        default :
                            $modulus = 0;
                            break;
                    }
                    $score += $temp * $modulus;
                }
            }
        } // 星体不在征象宫
        else
        {
            if (!empty($tr_planet1[$pid]['phase']))
            {
                foreach ($tr_planet1[$pid]['phase'] as $phase)
                {
                    // 与征象宫内星有相位
                    if (in_array($tr_planet1[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 太阳9月亮9金星4水星4火星3其它1
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp = 9;
                                break;
                            case 1:
                                $temp = 9;
                                break;
                            case 2:
                                $temp = 4;
                                break;
                            case 3:
                                $temp = 4;
                                break;
                            case 4:
                                $temp = 3;
                                break;
                            default:
                                $temp = 1;
                                break;
                        }
                        // 合0.8拱0.3刑1.5冲1.5六分0.2
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $modulus = 0.8;
                                break;
                            case 60:
                                $modulus = 0.2;
                                break;
                            case 90:
                                $modulus = 1.5;
                                break;
                            case 120:
                                $modulus = 0.3;
                                break;
                            case 180:
                                $modulus = 1.5;
                                break;
                            default :
                                $modulus = 0;
                                break;
                        }
                        $score += $temp * $modulus;
                    }
                }
            }
        }
        // 星体与征象星成相
        if (isset($tr_planet1[$pid]['phase'][$pid . '-' . $option['planet']]))
        {
            // 合5，刑冲12，拱六分3
            switch ($tr_planet1[$pid]['phase'][$pid . '-' . $option['planet']]['phase_e'])
            {
                case 0:
                    $temp = 5;
                    break;
                case 60:
                    $temp = 3;
                    break;
                case 90:
                    $temp = 12;
                    break;
                case 120:
                    $temp = 3;
                    break;
                case 180:
                    $temp = 12;
                    break;
                default :
                    $temp = 0;
                    break;
            }
            // （若征象星在征象宫内，此得分折半）
            if (in_array($tr_planet1[$option['planet']]['in_house_id'], $option['house']))
            {
                $temp *= 0.5;
            }
            $score += $temp;
        }
        //	tr引动
        if (!empty($tr_planet1[$pid]['phase']))
        {
            // 日月水金火
            $planets = [0, 2, 3, 4];
            // 遍历该星的相位
            foreach ($tr_planet1[$pid]['phase'] as $phase)
            {
                // 仅限日月水金火木土天海冥
                if ($phase['id'] < 10)
                {
                    foreach ($planets as $p)
                    {
                        /**
                         * 日金水火月与同该星成相的本命某星成相
                         * $pid 为该星
                         * $p 为日月水金火之一
                         * $phase['id'] 为本命某星
                         */
                        if ($pid != $p && isset($tr_planet1[$p]['phase'][$p . '-' . $phase['id']]))
                        {
                            /**
                             * 计算原相位力量
                             */
                            // 太阳9月亮9金星4水星4火星3其它1
                            switch ($phase['id'])
                            {
                                case 0:
                                    $temp1 = 9;
                                    break;
                                case 1:
                                    $temp1 = 0;
                                    break;
                                case 2:
                                    $temp1 = 4;
                                    break;
                                case 3:
                                    $temp1 = 4;
                                    break;
                                case 4:
                                    $temp1 = 3;
                                    break;
                                default:
                                    $temp1 = 1;
                                    break;
                            }
                            $temp2 = 0;
                            // 合1拱0.9刑0.9冲0.9六分0.8
                            // 合0.8拱0.3刑1.5冲1.5六分0.2
                            switch ($phase['phase_e'])
                            {
                                case 0:
                                    if (in_array($target_in_house, $option['house']))
                                    {
                                        $modulus = 1;
                                    } else
                                    {
                                        $modulus = 0.8;
                                    }
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 5;
                                    }
                                    break;
                                case 60:
                                    if (in_array($target_in_house, $option['house']))
                                    {
                                        $modulus = 0.8;
                                    } else
                                    {
                                        $modulus = 0.2;
                                    }
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 3;
                                    }
                                    break;
                                case 90:
                                    if (in_array($target_in_house, $option['house']))
                                    {
                                        $modulus = 0.9;
                                    } else
                                    {
                                        $modulus = 1.5;
                                    }
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 12;
                                    }
                                    break;
                                case 120:
                                    if (in_array($target_in_house, $option['house']))
                                    {
                                        $modulus = 0.9;
                                    } else
                                    {
                                        $modulus = 0.3;
                                    }
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 3;
                                    }
                                    break;
                                case 180:
                                    if (in_array($target_in_house, $option['house']))
                                    {
                                        $modulus = 0.9;
                                    } else
                                    {
                                        $modulus = 1.5;
                                    }
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 12;
                                    }
                                    break;
                                default :
                                    $modulus = 0;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 0;
                                    }
                                    break;
                            }
                            // 若征象星在征象宫内，此得分折半
                            if (in_array($tr_planet2[$phase['id']]['in_house_id'], $option['house']))
                            {
                                $temp2 *= 0.5;
                            }
                            // 原相位力量
                            $or_score = $temp1 * $modulus + $temp2;

                            /**
                             * 计算激发系数
                             */
                            $phase_boot = $tr_planet1[$p]['phase'][$p . '-' . $phase['id']];
                            // 0.5度内1
                            if ($phase_boot['phase_orb'] <= 0.5)
                            {
                                $temp1 = 1;
                            }// 1度内0.95
                            elseif ($phase_boot['phase_orb'] <= 1)
                            {
                                $temp1 = 0.95;
                            }// 1.5度内0.9
                            elseif ($phase_boot['phase_orb'] <= 1)
                            {
                                $temp1 = 0.9;
                            }// 2度内0.8
                            elseif ($phase_boot['phase_orb'] <= 2)
                            {
                                $temp1 = 0.8;
                            } else
                            {
                                $temp1 = 0;
                            }
                            // 日0.5月0.2水0.4金0.2火0.4
                            switch ($p)
                            {
                                case 0:
                                    $temp2 = 0.5;
                                    break;
                                case 1:
                                    $temp2 = 0;
                                    break;
                                case 2:
                                    $temp2 = 0.4;
                                    break;
                                case 3:
                                    $temp2 = 0.2;
                                    break;
                                case 4:
                                    $temp2 = 0.4;
                                    break;
                                default:
                                    $temp2 = 0;
                                    break;
                            }
                            // 合0.7，冲刑1，拱六分0.5
                            switch ($phase_boot['phase_e'])
                            {
                                case 0:
                                    $temp3 = 0.7;
                                    break;
                                case 60:
                                    $temp3 = 0.5;
                                    break;
                                case 90:
                                    $temp3 = 1;
                                    break;
                                case 120:
                                    $temp3 = 0.5;
                                    break;
                                case 180:
                                    $temp3 = 1;
                                    break;
                                default :
                                    $temp3 = 0;
                                    break;
                            }
                            // 激发原相位的力量的百分比（计算原相位力量而后乘以激发系数）
                            $score += $or_score * $temp1 * $temp2 * $temp3;
                        }
                    }
                }
            }
        }
        // 本命该星落在征象宫，被tr引动
        if (in_array($tr_planet2[$pid]['in_house_id'], $option['house']))
        {
            if (!empty($tr_planet2[$pid]['phase']))
            {
                foreach ($tr_planet2[$pid]['phase'] as $phase)
                {
                    if ($phase['id'] < 10)
                    {
                        // 天海冥2，木土3，火3.5，（金水4，日5，月3，仅在慢星引动时记分）
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp1 = 5;
                                break;
                            case 1:
                                $temp1 = 0;
                                break;
                            case 2:
                                $temp1 = 4;
                                break;
                            case 3:
                                $temp1 = 4;
                                break;
                            case 4:
                                $temp1 = 3.5;
                                break;
                            case 5:
                                $temp1 = 3;
                                break;
                            case 6:
                                $temp1 = 3;
                                break;
                            case 7:
                                $temp1 = 2;
                                break;
                            case 8:
                                $temp1 = 2;
                                break;
                            case 9:
                                $temp1 = 2;
                                break;
                            default :
                                $temp1 = 0;
                                break;
                        }
                        // 合1拱0.6刑1.2冲1.2六分0.6
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $temp2 = 1;
                                break;
                            case 60:
                                $temp2 = 0.6;
                                break;
                            case 90:
                                $temp2 = 1.2;
                                break;
                            case 120:
                                $temp2 = 0.6;
                                break;
                            case 180:
                                $temp2 = 1.2;
                                break;
                            default :
                                $temp2 = 0;
                                break;
                        }
                        $score += $temp1 * $temp2;
                    }
                }
            }
        }// 本命该星未落在征象宫，但被过征象宫的tr星引动
        else
        {
            if (!empty($tr_planet2[$pid]['phase']))
            {
                foreach ($tr_planet2[$pid]['phase'] as $phase)
                {
                    if ($phase['id'] < 10 && in_array($tr_planet1[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 天海冥2，木土3，火3.5，（金水4，日5，月3，仅在慢星引动时记分）
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp1 = 5;
                                break;
                            case 1:
                                $temp1 = 0;
                                break;
                            case 2:
                                $temp1 = 4;
                                break;
                            case 3:
                                $temp1 = 4;
                                break;
                            case 4:
                                $temp1 = 3.5;
                                break;
                            case 5:
                                $temp1 = 3;
                                break;
                            case 6:
                                $temp1 = 3;
                                break;
                            case 7:
                                $temp1 = 2;
                                break;
                            case 8:
                                $temp1 = 2;
                                break;
                            case 9:
                                $temp1 = 2;
                                break;
                            default :
                                $temp1 = 0;
                                break;
                        }
                        // 合1拱0.6刑1.2冲1.2六分0.6
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $temp2 = 1;
                                break;
                            case 60:
                                $temp2 = 0.6;
                                break;
                            case 90:
                                $temp2 = 1.2;
                                break;
                            case 120:
                                $temp2 = 0.6;
                                break;
                            case 180:
                                $temp2 = 1.2;
                                break;
                            default :
                                $temp2 = 0;
                                break;
                        }
                        $score += $temp1 * $temp2;
                    }
                }
            }
        }
        return $score;
    }

    /**
     * 星体对某方面的成就度（金木水）
     * @param array $source
     * @param array $option
     * target int 目标星体
     * house int 征象宫
     * planet int 征象星
     * @return float
     */
    public function getPlanetAchievementScore($source = [], $option = [])
    {
        $tr_planet1 = $source['transits_data'][1]['planets'];// 行运外盘数据 -天象
        $tr_planet2 = $source['transits_data'][0]['planets'];// 行运内盘数据 -本命
        $tp_planet = $source['thirdprogressed_data']['planets'];// 三限盘
        $pid = $option['target'];
        $limit = $option['planet_type'] ?? false;

        $score = 0;
        //	tp
        // 目标星三限落宫
        $target_in_house = $tp_planet[$pid]['in_house_id'];
        // 星体落在征象宫+3
        if (in_array($target_in_house, $option['house']))
        {
            $score += 3;
            // （若仅有该星落征象宫+5）
            if ($source['transits_data'][1]['houses'][$target_in_house]['have_planet_num'] == 1)
            {
                $score += 5;
            }
            // 有相位
            if (!empty($tp_planet[$pid]['phase']))
            {
                foreach ($tp_planet[$pid]['phase'] as $phase)
                {
                    // 太阳9月亮9金星4水星4木星4
                    switch ($phase['id'])
                    {
                        case 0:
                            $temp = 9;
                            break;
                        case 1:
                            $temp = 9;
                            break;
                        case 2:
                            $temp = 4;
                            break;
                        case 3:
                            $temp = 4;
                            break;
                        case 5:
                            $temp = 3;
                            break;
                        default:
                            $temp = 0;
                            break;
                    }
                    // 合1拱0.9刑0.4冲0.9六分0.8
                    switch ($phase['phase_e'])
                    {
                        case 0:
                            $modulus = 1;
                            break;
                        case 60:
                            $modulus = 0.8;
                            break;
                        case 90:
                            $modulus = 0.4;
                            break;
                        case 120:
                            $modulus = 0.9;
                            break;
                        case 180:
                            $modulus = 0.9;
                            break;
                        default :
                            $modulus = 0;
                            break;
                    }
                    $score += $temp * $modulus;
                }
            }
        } // 星体不在征象宫
        else
        {
            if (!empty($tp_planet[$pid]['phase']))
            {
                $is_phase_option_house_plaent = false;// 与征象宫内星有相位
                foreach ($tp_planet[$pid]['phase'] as $phase)
                {
                    // 与征象宫内星有相位
                    if (in_array($tp_planet[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 太阳9月亮9金星4水星4木星4
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp = 9;
                                break;
                            case 1:
                                $temp = 9;
                                break;
                            case 2:
                                $temp = 4;
                                break;
                            case 3:
                                $temp = 4;
                                break;
                            case 5:
                                $temp = 4;
                                break;
                            default:
                                $temp = 0;
                                break;
                        }
                        // 合1拱0.9刑0.4冲0.9六分0.8
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $modulus = 1;
                                break;
                            case 60:
                                $modulus = 0.8;
                                break;
                            case 90:
                                $modulus = 0.4;
                                break;
                            case 120:
                                $modulus = 0.9;
                                break;
                            case 180:
                                $modulus = 0.9;
                                break;
                            default :
                                $modulus = 0;
                                break;
                        }
                        $score += $temp * $modulus;

                        $is_phase_option_house_plaent = true;
                    }
                }
                // 如月亮未在征象宫内，该星在与征象宫星体成相的同时与月亮成相
                if (!in_array($tp_planet[1]['in_house_id'], $option['house'])
                    && $is_phase_option_house_plaent === true
                    && isset($tp_planet[$pid]['phase'][$pid . '-1'])
                )
                {
                    // 刑0.3冲0.9合1拱1六分0.8
                    switch ($tp_planet[$pid]['phase'][$pid . '-1']['phase_e'])
                    {
                        case 0:
                            $temp = 1;
                            break;
                        case 60:
                            $temp = 0.8;
                            break;
                        case 90:
                            $temp = 0.3;
                            break;
                        case 120:
                            $temp = 1;
                            break;
                        case 180:
                            $temp = 0.9;
                            break;
                        default :
                            $temp = 0;
                            break;
                    }
                    $score += $temp;
                }
            }
        }
        // 星体与征象星成相
        if (($limit === false && $pid != 1) && isset($tp_planet[$pid]['phase'][$pid . '-' . $option['planet']]))
        {
            // 合13，拱冲12，六分10，刑4
            switch ($tp_planet[$pid]['phase'][$pid . '-' . $option['planet']]['phase_e'])
            {
                case 0:
                    $temp = 13;
                    break;
                case 60:
                    $temp = 10;
                    break;
                case 90:
                    $temp = 4;
                    break;
                case 120:
                    $temp = 12;
                    break;
                case 180:
                    $temp = 12;
                    break;
                default :
                    $temp = 0;
                    break;
            }
            // （若征象星在征象宫内，此得分折半）
            if (in_array($tp_planet[$option['planet']]['in_house_id'], $option['house']))
            {
                $temp *= 0.5;
            }
            $score += $temp;
        }
        //	tr
        //		星体落在征象宫+3
        if (in_array($tr_planet1[$pid]['in_house_id'], $option['house']))
        {
            $score += 3;
            // 有相位
            if (!empty($tr_planet1[$pid]['phase']))
            {
                foreach ($tr_planet1[$pid]['phase'] as $phase)
                {
                    // 太阳9月亮9金星4水星4木星4
                    switch ($phase['id'])
                    {
                        case 0:
                            $temp = 9;
                            break;
                        case 1:
                            $temp = 9;
                            break;
                        case 2:
                            $temp = 4;
                            break;
                        case 3:
                            $temp = 4;
                            break;
                        case 5:
                            $temp = 4;
                            break;
                        default:
                            $temp = 0;
                            break;
                    }
                    // 合1拱0.9刑0.4冲0.9六分0.8
                    switch ($phase['phase_e'])
                    {
                        case 0:
                            $modulus = 1;
                            break;
                        case 60:
                            $modulus = 0.8;
                            break;
                        case 90:
                            $modulus = 0.4;
                            break;
                        case 120:
                            $modulus = 0.9;
                            break;
                        case 180:
                            $modulus = 0.9;
                            break;
                        default :
                            $modulus = 0;
                            break;
                    }
                    $score += $temp * $modulus;
                }
            }
        } // 星体不在征象宫
        else
        {
            if (!empty($tr_planet1[$pid]['phase']))
            {
                foreach ($tr_planet1[$pid]['phase'] as $phase)
                {
                    // 与征象宫内星有相位
                    if (in_array($tr_planet1[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 太阳9月亮9金星4水星4木星4
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp = 9;
                                break;
                            case 1:
                                $temp = 9;
                                break;
                            case 2:
                                $temp = 4;
                                break;
                            case 3:
                                $temp = 4;
                                break;
                            case 5:
                                $temp = 4;
                                break;
                            default:
                                $temp = 0;
                                break;
                        }
                        // 合1拱0.9刑0.4冲0.9六分0.8
                        switch ($phase['phase_e'])
                        {
                            case 0:
                                $modulus = 1;
                                break;
                            case 60:
                                $modulus = 0.8;
                                break;
                            case 90:
                                $modulus = 0.4;
                                break;
                            case 120:
                                $modulus = 0.9;
                                break;
                            case 180:
                                $modulus = 0.9;
                                break;
                            default :
                                $modulus = 0;
                                break;
                        }
                        $score += $temp * $modulus;
                    }
                }
            }
        }
        // 星体与征象星成相
        if (isset($tr_planet1[$pid]['phase'][$pid . '-' . $option['planet']]))
        {
            // 合13，拱冲12，六分10，刑4
            switch ($tr_planet1[$pid]['phase'][$pid . '-' . $option['planet']]['phase_e'])
            {
                case 0:
                    $temp = 13;
                    break;
                case 60:
                    $temp = 10;
                    break;
                case 90:
                    $temp = 4;
                    break;
                case 120:
                    $temp = 12;
                    break;
                case 180:
                    $temp = 12;
                    break;
                default :
                    $temp = 0;
                    break;
            }
            // （若征象星在征象宫内，此得分折半）
            if (in_array($tr_planet1[$option['planet']]['in_house_id'], $option['house']))
            {
                $temp *= 0.5;
            }
            $score += $temp;
        }
        //	tr引动
        if (!empty($tr_planet1[$pid]['phase']))
        {
            // 日月水金火
            $planets = [0, 2, 3, 4];
            // 遍历该星的相位
            foreach ($tr_planet1[$pid]['phase'] as $phase)
            {
                // 仅限日月水金火木土天海冥
                if ($phase['id'] < 10)
                {
                    foreach ($planets as $p)
                    {
                        /**
                         * 日金水火月与同该星成相的本命某星成相
                         * $pid 为该星
                         * $p 为日月水金火之一
                         * $phase['id'] 为本命某星
                         */
                        if ($pid != $p && isset($tr_planet1[$p]['phase'][$p . '-' . $phase['id']]))
                        {
                            /**
                             * 计算原相位力量
                             */
                            // 太阳9月亮9金星4水星4木星4
                            switch ($phase['id'])
                            {
                                case 0:
                                    $temp1 = 9;
                                    break;
                                case 1:
                                    $temp1 = 0;
                                    break;
                                case 2:
                                    $temp1 = 4;
                                    break;
                                case 3:
                                    $temp1 = 4;
                                    break;
                                case 5:
                                    $temp1 = 4;
                                    break;
                                default:
                                    $temp1 = 0;
                                    break;
                            }
                            $temp2 = 0;
                            // 合1拱0.9刑0.4冲0.9六分0.8
                            // 合13，拱冲12，六分10，刑4
                            switch ($phase['phase_e'])
                            {
                                case 0:
                                    $modulus = 1;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 13;
                                    }
                                    break;
                                case 60:
                                    $modulus = 0.8;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 10;
                                    }
                                    break;
                                case 90:
                                    $modulus = 0.4;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 4;
                                    }
                                    break;
                                case 120:
                                    $modulus = 0.9;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 12;
                                    }
                                    break;
                                case 180:
                                    $modulus = 0.9;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 12;
                                    }
                                    break;
                                default :
                                    $modulus = 0;
                                    if ($phase['id'] == $option['planet'])
                                    {
                                        $temp2 = 0;
                                    }
                                    break;
                            }
                            // 若征象星在征象宫内，此得分折半
                            if (in_array($tr_planet2[$phase['id']]['in_house_id'], $option['house']))
                            {
                                $temp2 *= 0.5;
                            }
                            // 原相位力量
                            $or_score = $temp1 * $modulus + $temp2;

                            /**
                             * 计算激发系数
                             */
                            $phase_boot = $tr_planet1[$p]['phase'][$p . '-' . $phase['id']];
                            // 0.5度内1
                            if ($phase_boot['phase_orb'] <= 0.5)
                            {
                                $temp1 = 1;
                            }// 1度内0.95
                            elseif ($phase_boot['phase_orb'] <= 1)
                            {
                                $temp1 = 0.95;
                            }// 1.5度内0.9
                            elseif ($phase_boot['phase_orb'] <= 1)
                            {
                                $temp1 = 0.9;
                            }// 2度内0.8
                            elseif ($phase_boot['phase_orb'] <= 2)
                            {
                                $temp1 = 0.8;
                            } else
                            {
                                $temp1 = 0;
                            }
                            // 日0.5月0.2水0.4金0.4火0.4
                            switch ($p)
                            {
                                case 0:
                                    $temp2 = 0.5;
                                    break;
                                case 1:
                                    $temp2 = 0;
                                    break;
                                case 2:
                                    $temp2 = 0.4;
                                    break;
                                case 3:
                                    $temp2 = 0.4;
                                    break;
                                case 4:
                                    $temp2 = 0.4;
                                    break;
                                default:
                                    $temp2 = 0;
                                    break;
                            }
                            if ($phase['id'] == 4)
                            {
                                // 火星合0.5刑0.1冲0.1拱0.5六分0.4
                                switch ($phase_boot['phase_e'])
                                {
                                    case 0:
                                        $temp3 = 0.5;
                                        break;
                                    case 60:
                                        $temp3 = 0.4;
                                        break;
                                    case 90:
                                        $temp3 = 0.1;
                                        break;
                                    case 120:
                                        $temp3 = 0.5;
                                        break;
                                    case 180:
                                        $temp3 = 0.1;
                                        break;
                                    default :
                                        $temp3 = 0;
                                        break;
                                }
                            } else
                            {
                                // 合1刑0.2冲0.8拱0.9六分0.8
                                switch ($phase_boot['phase_e'])
                                {
                                    case 0:
                                        $temp3 = 1;
                                        break;
                                    case 60:
                                        $temp3 = 0.8;
                                        break;
                                    case 90:
                                        $temp3 = 0.2;
                                        break;
                                    case 120:
                                        $temp3 = 0.9;
                                        break;
                                    case 180:
                                        $temp3 = 0.8;
                                        break;
                                    default :
                                        $temp3 = 0;
                                        break;
                                }
                            }
                            // 激发原相位的力量的百分比（计算原相位力量而后乘以激发系数）
                            $score += $or_score * $temp1 * $temp2 * $temp3;
                        }
                    }
                }
            }
        }
        // 本命该星落在征象宫，被tr引动
        if (in_array($tr_planet2[$pid]['in_house_id'], $option['house']))
        {
            if (!empty($tr_planet2[$pid]['phase']))
            {
                foreach ($tr_planet2[$pid]['phase'] as $phase)
                {
                    if ($phase['id'] < 10)
                    {
                        // 天2，木3，火2（金水4，日5，月3，仅在慢星引动时记分）
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp1 = 5;
                                break;
                            case 1:
                                $temp1 = 0;
                                break;
                            case 2:
                                $temp1 = 4;
                                break;
                            case 3:
                                $temp1 = 4;
                                break;
                            case 4:
                                $temp1 = 2;
                                break;
                            case 5:
                                $temp1 = 3;
                                break;
                            case 7:
                                $temp1 = 2;
                                break;
                            default :
                                $temp1 = 0;
                                break;
                        }
                        if ($phase['id'] == 4)
                        {
                            // 火星合0.5刑0.1冲0.1拱0.5六分0.4
                            switch ($phase['phase_e'])
                            {
                                case 0:
                                    $temp2 = 0.5;
                                    break;
                                case 60:
                                    $temp2 = 0.4;
                                    break;
                                case 90:
                                    $temp2 = 0.1;
                                    break;
                                case 120:
                                    $temp2 = 0.5;
                                    break;
                                case 180:
                                    $temp2 = 0.1;
                                    break;
                                default :
                                    $temp2 = 0;
                                    break;
                            }
                        } else
                        {
                            // 合1刑0.2冲0.8拱0.9六分0.8
                            switch ($phase['phase_e'])
                            {
                                case 0:
                                    $temp2 = 1;
                                    break;
                                case 60:
                                    $temp2 = 0.8;
                                    break;
                                case 90:
                                    $temp2 = 0.2;
                                    break;
                                case 120:
                                    $temp2 = 0.9;
                                    break;
                                case 180:
                                    $temp2 = 0.8;
                                    break;
                                default :
                                    $temp2 = 0;
                                    break;
                            }
                        }
                        $score += $temp1 * $temp2;
                    }
                }
            }
        }// 本命该星未落在征象宫，但被过征象宫的tr星引动
        else
        {
            if (!empty($tr_planet2[$pid]['phase']))
            {
                foreach ($tr_planet2[$pid]['phase'] as $phase)
                {
                    if ($phase['id'] < 10 && in_array($tr_planet1[$phase['id']]['in_house_id'], $option['house']))
                    {
                        // 天2，木3，火2（金水4，日5，月3，仅在慢星引动时记分）
                        switch ($phase['id'])
                        {
                            case 0:
                                $temp1 = 5;
                                break;
                            case 1:
                                $temp1 = 0;
                                break;
                            case 2:
                                $temp1 = 4;
                                break;
                            case 3:
                                $temp1 = 4;
                                break;
                            case 4:
                                $temp1 = 2;
                                break;
                            case 5:
                                $temp1 = 3;
                                break;
                            case 7:
                                $temp1 = 2;
                                break;
                            default :
                                $temp1 = 0;
                                break;
                        }
                        if ($phase['id'] == 4)
                        {
                            // 火星合0.5刑0.1冲0.1拱0.5六分0.4
                            switch ($phase['phase_e'])
                            {
                                case 0:
                                    $temp2 = 0.5;
                                    break;
                                case 60:
                                    $temp2 = 0.4;
                                    break;
                                case 90:
                                    $temp2 = 0.1;
                                    break;
                                case 120:
                                    $temp2 = 0.5;
                                    break;
                                case 180:
                                    $temp2 = 0.1;
                                    break;
                                default :
                                    $temp2 = 0;
                                    break;
                            }
                        } else
                        {
                            // 合1刑0.2冲0.8拱0.9六分0.8
                            switch ($phase['phase_e'])
                            {
                                case 0:
                                    $temp2 = 1;
                                    break;
                                case 60:
                                    $temp2 = 0.8;
                                    break;
                                case 90:
                                    $temp2 = 0.2;
                                    break;
                                case 120:
                                    $temp2 = 0.9;
                                    break;
                                case 180:
                                    $temp2 = 0.8;
                                    break;
                                default :
                                    $temp2 = 0;
                                    break;
                            }
                        }
                        $score += $temp1 * $temp2;
                    }
                }
            }
        }
        return $score;
    }
}
